#pragma once
/*
 * defer class.
 */
#include <functional>

namespace anet {
	namespace utils {
		// defer class.
		class CDefer final {
		public:
			explicit CDefer(std::function<void()> f) : m_deferFlag(true),
				m_deferFunc(std::move(f)) {
			}
			~CDefer() {
				if (m_deferFlag) {
					m_deferFunc();
				}
			}

			void SetDeferFlag(bool flag) {
				m_deferFlag = flag;
			}

		private:
			bool m_deferFlag{ false };
			std::function<void()> m_deferFunc;
		};
	}
}